<template>
  <div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span>
        <el-form ref="form" :model="arr" label-width="80px" :rules="rules">
          <el-form-item label="名字" prop="username">
            <el-input
              placeholder="请输入名字"
              v-model="arr.username"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              placeholder="请输入密码"
              show-password
              v-model="arr.password"
            ></el-input>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">登录</el-button>
        <el-button @click="resetForm">重置</el-button>
   
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: true,
      arr: {
        username: "admin",
        password:"123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 7, message: "长度在 3 到 7 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "change" },
        ],
      },
    };
  },
  methods: {
 
    submitForm() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
         
        let {data:res}= await this.axios.post("/login",this.arr
              
       )          
 
       if(res.meta.status ==200){
          localStorage.setItem('todo',res.data.token)
          this.$router.push('/hh')
       }else{
             this.$message({
            message: "登录失败",
            type: "warning",
          });
       }
           

          this.$message({
            message: "登录成功了",
            type: "success",
          });
        } else {
          this.$message({
            message: "登录失败",
            type: "warning",
          });
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
  },
};
</script>
<style lang="scss" scoped>

</style>